/**
 * Ingenius-Group S.A.S
 *
 * Project: SAU
 * File: LinkImage.java
 * Date: 12/03/2011
 */

package com.ingenius.sau.client.view.widgets;

import com.extjs.gxt.ui.client.widget.Html;

/**
 * Class <strong>LinkImage</strong>
 * 
 * @author Jesus David
 * @version 0.1
 */
public class LinkImage extends Html {

	public enum LinkImageStatus {
		active, disable, enable
	}

	static final String advancedLink = "<div class='%s'><a onmouseover='className=\"%s\"' onmouseout='className=\"%s\"'><img src='%s' onmousedown='event.preventDefault()'></img><p>%s</p></a></div>";

	static final String simpleLink = "<div class='%s'><a class='%s'><img src='%s' onmousedown='event.preventDefault()'></img><p>%s</p></a></div>";

	private String linkText;

	private String iconUrl;

	private LinkImageStatus status;

	public LinkImage(String text, String iconUrl) {
		setLinkText(text);
		setIconUrl(iconUrl);
		setStatus(LinkImageStatus.enable);
		createWidget();
	}

	private void createWidget() {
		String styleName = "link-image";
		String html;

		switch (status) {
		case active:
			html = StringUtil.format(simpleLink, styleName, "zoom", iconUrl,
					linkText);

			break;

		case disable:
			html = StringUtil.format(simpleLink, styleName, "disable", iconUrl,
					linkText);
			break;

		default:
			html = StringUtil.format(advancedLink, styleName, "zoom", "enable",
					iconUrl, linkText);
			break;
		}
		setHtml(html);
	}

	public String getLinkText() {
		return linkText;
	}

	public void setLinkText(String linkText) {
		this.linkText = linkText;
	}

	public String getIconUrl() {
		return iconUrl;
	}

	public void setIconUrl(String iconUrl) {
		this.iconUrl = iconUrl;
	}

	public LinkImageStatus getStatus() {
		return status;
	}

	public void setStatus(LinkImageStatus status) {
		this.status = status;
		createWidget();
	}
}
